﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;



namespace AbatDeployer
{
    class Program
    {
        
        static void Main(string[] args)
        {
            string localizeFilePath = null, EnvironmentName = null, SchedulerName = null;

            if (args.Count()==3)
            {
                SchedulerName = args[0];
                localizeFilePath = args[1];

                EnvironmentName = args[2];
            }
            else
            {
                //Throw exeption here 
            }

            try
            {

                ActiveBatch.AbatJobScheduler scheduler = new ActiveBatch.AbatJobScheduler();

                //Connect to scheduler
                scheduler.Connect(SchedulerName, null, null, false);

                //get the localized object of the config file 
                ConfigFileReader conf = new ConfigFileReader(localizeFilePath);
                AbatModel abatModel = conf.readXmlFile(EnvironmentName);

                //localize variables 
                AbatHelper abathelper = new AbatHelper();

                foreach (string VarPath in abatModel.ABATVariablesPath)
                {
                    abathelper.localizeVariable(abatModel, VarPath, scheduler);
                }

                //Localize queues

                foreach (string VarPath in abatModel.ABATQueuesPath)
                {
                    abathelper.localizeQueues(abatModel, VarPath, scheduler);
                }
                

                //localize web reference 
                foreach (string VarPath in abatModel.ABATSRsPath)
                {

                    abathelper.localize_serviceReference(abatModel, VarPath, scheduler);
                }
                //localize service account 
                foreach (string VarPath in abatModel.ABATUserAccountsPath)
                {


                    abathelper.localize_serviceAccount(abatModel, VarPath, scheduler);

                }
             

             
            }


            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }




            System.Console.ReadKey();


        }
    }
}
